package com.example.firstspringboot.controller;

import com.example.firstspringboot.bean.Book;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    static List<Book> books;

    static {
        books = new ArrayList<>();
        books.add(new Book(1, "JavaEE开发实战", 60, true, 2));
        books.add(new Book(2, "Vue开发实战", 50, true, 1));
    }

    @GetMapping("/list")
    public List<Book> getCarList() {
        return books;
    }

    @PostMapping("/delete/{id}")
    public Boolean delete(@PathVariable int id) {
        for (Book book : books) {
            if (book.getId() == id) {
                books.remove(book);
                System.out.println("删除成功");
                return true;
            }
        }
        return false;
    }

    @PostMapping("/submit")
    public Boolean submit(@RequestBody List<Book> bookList) {
        for (Book book : bookList) {
            System.out.println(book);
        }
        return true;
    }
}